package controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class FilterController {
	
	/*
	 * 利用传统方法解决读取参数的乱码问题
	@RequestMapping("/toLogin.do")
	public String toLogin() throws UnsupportedEncodingException {
		System.out.println("toLogin()"); 
		request.setCharacterEncoding("utf-8"); //利用传统方法解决中文乱码（需要抛出异常）
		return "toLogin";
	}
	*/
	
	@RequestMapping("/toLogin.do")
	public String toLogin(){
		System.out.println("toLogin()"); 
		return "toLogin";
	}
	
	@RequestMapping("index.do")
	/*
	 * 利用 springMVC 提供的过滤器来解决浏览器请求参数的乱码问题（直接在web.xml中进行配置就行啦）
	 */
	public String login(HttpServletRequest request) {
		System.out.println("login()");
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		System.out.println("username :" + username);
		System.out.println("password ：" + password);
		request.setAttribute("username", username);
		return "index";
	}
}
